package com.hua.designpattern.behavioral.command;

import java.util.ArrayList;
import java.util.List;

public class CommandBag {
	private List<CommandInterface> commands = new ArrayList<CommandInterface>();

	public void doEdit(CommandInterface command) {
		System.out.println("----add command!!");
		commands.add(command);
	}

	public void revokeLast() {
		System.out.println("----remove last command!!");
		commands.remove(commands.size() == 0 ? 0 : commands.size() - 1);
	}

	public void doSubmit() {
		System.out.println("++++execute all command!!");
		for (CommandInterface command : commands) {
			command.execute();
		}
	}
}
